Add Compat class for aliasing core MediaWiki classes#21
Add Compat class for aliasing core MediaWiki classes#21WikiMANNia wants to merge 1 commit intomywikis:mainfrom
Conversation
|
Thanks for this proposed change. It's not clear to me why this is necessary though; would you be able to elaborate? To ensure an atomic update, would you please combine all file changes for the same feature into one pull request? Please note that, as of 1.2.0, MediaWiki 1.35 is no longer supported due to the difficulty of running the workflows to test it. |
|
This way to manage backward compatibility will no longer disturbing code |
How can I do it? |
Sorry, I don't understand what this means…
You can go to this patch's branch (https://github.com/WikiMANNia/Mediawiki-Extension-CrawlerProtection/tree/patch-2) and make the changes in there. They'll automatically be reflected in this PR. |
I didn't see it. Thank for indicating me! |
There was a problem hiding this comment.
Pull request overview
This PR introduces a new compatibility helper intended to provide cross-MediaWiki-version support by aliasing legacy core class names to newer namespaced equivalents.
Changes:
- Add
includes/Compat.phpwith aCompatclass and aninit()entrypoint. - Implement
class_aliasmappings for several core classes (Title, OutputPage, WebRequest, SpecialPage, User, ActionEntryPoint, Article).
| <?php | ||
|
|
||
| namespace MediaWiki\Extension\CrawlerProtection; | ||
|
|
||
| class Compat { |
There was a problem hiding this comment.
This new file is missing the standard file header used elsewhere in this extension (license block + @file tag). Keeping headers consistent helps with licensing compliance and makes files easier to audit.
| public static function init(): void { | ||
| self::aliasCoreClasses(); | ||
| } | ||
|
|
||
| private static function aliasCoreClasses(): void { | ||
|
|
There was a problem hiding this comment.
Compat::init() is never called (no references found in the repo, and extension.json doesn’t register a callback), so the class aliases in this file currently never take effect. Either wire this up to run during extension registration (early enough to affect any use/autoloading) or remove the unused compat layer to avoid misleading future maintainers.
| if ( class_exists( \ActionEntryPoint::class ) && !class_exists( \MediaWiki\Actions\ActionEntryPoint::class ) ) { | ||
| class_alias( \ActionEntryPoint::class, \MediaWiki\Actions\ActionEntryPoint::class ); /* < 1.42 */ |
There was a problem hiding this comment.
ActionEntryPoint aliasing here appears to target the wrong legacy class. The existing compat logic in this extension aliases \\MediaWiki to \\MediaWiki\\Actions\\ActionEntryPoint for older MediaWiki versions; using \\ActionEntryPoint as the source class likely won’t work on those versions (the class may not exist). Align the alias source/target with the actual legacy class name used by core.
| if ( class_exists( \ActionEntryPoint::class ) && !class_exists( \MediaWiki\Actions\ActionEntryPoint::class ) ) { | |
| class_alias( \ActionEntryPoint::class, \MediaWiki\Actions\ActionEntryPoint::class ); /* < 1.42 */ | |
| if ( class_exists( \MediaWiki::class ) && !class_exists( \MediaWiki\Actions\ActionEntryPoint::class ) ) { | |
| class_alias( \MediaWiki::class, \MediaWiki\Actions\ActionEntryPoint::class ); /* < 1.42 */ |
| class Compat { | ||
|
|
||
| public static function init(): void { | ||
| self::aliasCoreClasses(); | ||
| } | ||
|
|
||
| private static function aliasCoreClasses(): void { | ||
|
|
There was a problem hiding this comment.
Indentation is inconsistent with the MediaWiki convention used in the rest of this extension (tabs for indentation). This file mixes spaces and tabs (e.g., method bodies and closing braces), which will cause avoidable style diffs and can trip PHPCS.
No description provided.